package com.sikao.app.ui;

import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.widget.ImageView;
import android.widget.TextView;

import com.sikao.app.R;
import com.sikao.app.bean.MyMailBean;
import com.sikao.app.ui.base.BaseActivity;
import com.sikao.app.utils.TimeUtil;

/**
 * 站内信详情
 */
public class MyMailDetailsActivity extends BaseActivity implements View.OnClickListener{

	private TextView titleTv;
	private ImageView backIv;
	private TextView themeTv;
	private TextView sendTv;
	private TextView typeTv;
	private TextView nameTv;
	private TextView timeTv;
	private TextView contentTv;
	private int type;//0代表收到的站内信，1代表发送的站内信

	private MyMailBean.ResBean.ListBean bean;

	@Override
	protected void onCreate(Bundle savedInstanceState) {
		setContentView(R.layout.activity_my_mail_details);
		super.onCreate(savedInstanceState);
	}

	@Override
	protected void initData() {
		type = getIntent().getIntExtra("type",0);
		Bundle bundle = getIntent().getBundleExtra("bundle");
		bean = (MyMailBean.ResBean.ListBean) bundle.get("bean");
	}

	@Override
	protected void initView() {
		titleTv = (TextView) findViewById(R.id.title_middle_tv);
		backIv = (ImageView) findViewById(R.id.title_left_img);
		sendTv = (TextView) findViewById(R.id.title_right_tv);
		themeTv = (TextView) findViewById(R.id.theme_tv);
		typeTv = (TextView) findViewById(R.id.type_tv);
		nameTv = (TextView) findViewById(R.id.name_tv);
		timeTv = (TextView) findViewById(R.id.time_tv);
		contentTv = (TextView) findViewById(R.id.content_tv);
	}

	@Override
	protected void initListener() {
		backIv.setOnClickListener(this);
		sendTv.setOnClickListener(this);
	}

	@Override
	protected void init() {
		titleTv.setText("站内信详情");
		backIv.setVisibility(View.VISIBLE);
		themeTv.setText(bean.getTitle());
		contentTv.setText(bean.getContent());
		timeTv.setText(TimeUtil.timeStampToTime(bean.getCreate_time(),TimeUtil.fotmatString2));
		if (type == 0){
			typeTv.setText("发件人：");
			nameTv.setText(bean.getFromName());
			sendTv.setVisibility(View.VISIBLE);
			sendTv.setText("回复");
		}else{
			typeTv.setText("收件人：");
			nameTv.setText(bean.getToName());
		}
	}

	@Override
	public void onClick(View v) {
		switch (v.getId()){
			case R.id.title_left_img :
				finish();
				break;
			case R.id.title_right_tv :
				Intent intent = new Intent(MyMailDetailsActivity.this,SendMailActivity.class);
				intent.putExtra("type","name");
				intent.putExtra("value",bean.getFromName());
				startActivity(intent);
				break;
			default:
				break;
		}
	}

}
